<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/usercenter.css?v=<?php echo Yii::app()->params['version']['CSS'];?>"/>
<div class="cont">
	<div class="user_set">
    	<h2>账号设置</h2>
        <ul>
        	<li>
            	<i class="ico_email"></i>
                <span>邮箱：</span>
				<?php if(empty($userData['email'])){?>
				<p><em>请输入邮箱</em></p>
				<?php }else{?>
				<p><?php echo $userData['email'];?></p>
				<?php }?>
                <a href="javascript:void(0);" class="btn_change" method="email">更改邮箱</a>
            </li>
        	<li class="pwd">
            	<i class="ico_pwd"></i>
                <span>密码：</span>
                <p>**********</p>
                <div class="alert_set">
                    <strong><b>请输入密码：</b><input type="password" class="t" name="passwd" id="passwd" placeholder="输入6位以上密码" /></strong>
                    <strong><b>请输入新密码：</b><input type="password" class="t" name="repasswd" id="repasswd" placeholder="输入6位以上密码" /></strong>
                    <strong><b>请再次输入新密码：</b><input type="password" class="t" name="newpasswd" id="newpasswd" placeholder="输入6位以上密码" /></strong>
                </div>
                <a href="javascript:void(0);" class="btn_change_pwd" method="change_passwd">修改</a>
            </li>
        	<li>
            	<i class="ico_tel"></i>
                <span>手机：</span>
				<?php if(empty($userData['mobile'])){?>
				<p><em>绑定后方便为您确定行程</em></p>
				<?php }else{?>
				<p><?php echo $userData['mobile'];?></p>
				<?php }?>
                <a href="javascript:void(0);" class="btn_change"  method="mobile">绑定</a>
            </li>
        	<li>
            	<i class="ico_name"></i>
                <span>昵称：</span>
				<?php if(empty($userData['nick_name'])){?>
				<p><em>行走江湖， 取一个任性的名字吧！</em></p>
				<?php }else{?>
				<p><?php echo $userData['nick_name'];?></p>
				<?php }?>
                <a href="javascript:void(0);" class="btn_change"  method="nick_name">设置</a>
            </li>
        </ul>
    </div>
	<?php $this->beginWidget('application.widget.order.orderList', array('currentPage'=>$currentPage)); ?>
	<?php $this->endWidget(); ?>
</div>
<div class="cont">
	<!--你感兴趣的-->
    <?php $this->beginWidget('application.widget.produce.interest'); ?>
	<?php $this->endWidget(); ?>
</div>
<script type="text/javascript">
$(".info img,.user_ins img").zoom();

$(".user_set li").each(function(index, element) {
    var $par = $(this);
	var $btn = $par.find(".btn_change");
	var btnText = $btn.text();
	var $wrap = $par.find("p");
	var text = $wrap.text();
	var place = $wrap.find("em").text();
	$wrap.attr("data-place",place);
	
	$btn.click(function(){
		if($wrap.has("input").length == 0){
			var $input = $('<input type="text" class="t">');
			$wrap.html($input);
			if(place == ""){
				$input.val(text);
				$input.focus().select();
			}else{
				$input.attr("placeholder",place);
				$input.focus();
			}
			$btn.text("保存");
		}else{
			var val = $.trim($wrap.find("input").val());
			if(val == ""){
				$.jGrowl("请输入修改信息");
				return false;
			}
			user_set({method:$(this).attr("method"), val:val});
			if(val != "" || modifyFlag == false){
				text = val;
				place = "";
				$wrap.html(val);
			}else{
				$wrap.html('<em>' + $wrap.attr("data-place") + '</em>');
			}
			$btn.text(btnText);
		}
	});
});

$(".user_set .btn_change_pwd").click(function(){
	if($(".user_set .alert_set").is(":visible")){
		var passwd = $("input[name=passwd]").val();
		var repasswd = $("input[name=repasswd]").val();
		var newpasswd = $("input[name=newpasswd]").val();
		if(passwd == "" || repasswd == "" || repasswd == ""){
			$.jGrowl("请输入完整密码");
			return false;
		}
		user_set({method:$(this).attr("method"), passwd:passwd, repasswd:repasswd, newpasswd:newpasswd});
		$(".user_set .alert_set").stop(true).fadeOut();
		$(".user_set .alert_set input").val("");
		$(this).text("修改");
	}else{
		$(".user_set .alert_set").stop(true).fadeIn();
		$(this).text("保存");
	}
});

$(document).on("click",function(e){
	if($(e.target).closest(".user_set li.pwd").length == 0 && $(".user_set .alert_set:visible")){
		$(".user_set .alert_set").fadeOut();
		$(".user_set .btn_change_pwd").text("修改");
	}
});
var modifyFlag = false;
function user_set(data){
	modifyFlag = false;
	var req = {};
	req.url = "<?php echo Yii::app()->createUrl('user/modify');?>";
	req.type = "post";
	req.dataType = "JSON";
	req.async = false;
	req.cache = false;
	req.data = data;
	req.error = function(){$.jGrowl("貌似有点问题哦~");};
	req.success = function(msg){
		if(msg.header.status == 0){
			$.jGrowl("修改成功");
			modifyFlag = true;
		}else{
			$.jGrowl(msg.header.reqMsg);
		}
	};
	req.time = 5000;
	$.ajax(req);
}
/*function show_msg_box(msg){
	$(".alert.fail span").html("8秒后关闭");
	$(".alert.fail").show();
	$(".alert.fail p").html(msg);
	var time = 8;
	intval = setInterval(function(){
		time--;
		$(".alert.fail span").html(time + "秒后关闭");
		if(time <= 0){
			clearInterval(intval);
			$(".alert.fail").hide();
		}
	}, 1000);
}
$(".alert.fail a").on("click", function(){
	clearInterval(intval);
	$(".alert.fail").hide();
});*/
</script>